package com.bkhech.apisix.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

@RestController
@SpringBootApplication
public class ApisixApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApisixApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam String param) {
        return "[server " + getLocalIp() + " response] hello: " + param;
    }

    @GetMapping("/world")
    public String world(@RequestParam String param) {
        return "[server " + getLocalIp() + " response] world: " + param;
    }

    private String getLocalIp() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return "empty";
    }

}
